package com.my.gitspringboot.controller;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

@Controller
public class test {

    private static int num = 0;

    @ResponseBody
    @RequestMapping("/test")
    public String test(HttpServletRequest req){
        num = new BigDecimal((Math.random()*10)).setScale(0, BigDecimal.ROUND_DOWN).intValue();
        String v1 = req.getParameter("v1");
        System.out.println(v1);
        String msg;
        if(String.valueOf(num).equals(v1)){
            msg = "<script>alert('正确！'); window.location.href=\"/\";</script>";
        }else{
            msg = "<script>alert('错误！"+num+"'); window.location.href=\"/\";</script>";
        }
        return msg;
    }
}
